<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="${staticServer}/inc/style/main.css" />
<link rel="stylesheet" href="${staticServer}/inc/style/page.css" />
<link rel="stylesheet" href="${staticServer}/css/struct_info.css" />
<script src="${staticServer}/inc/js/jquery.js"></script>
<script src="${staticServer}/inc/js/pageset.js"></script>
<script src="${staticServer}/inc/js/submitter.js"></script>
<script src="${staticServer}/inc/js/infopad.js?2.2"></script>
<script type="text/javascript" src="${staticServer}/common/uploadify/jquery.uploadify.js"></script>
<script type="text/javascript" src="${staticServer}/js/web/uploadImg.js?1.5"></script>

<link rel="stylesheet" href="${staticServer}/inc/style/date/datepicker.css" />
<script src="${staticServer}/inc/js/datepicker.js"></script>
<script type="text/javascript" src="${staticServer}/common/My97DatePicker/WdatePicker.js"></script>
<style>
#SWFUpload_0{
	margin-top: 70px;
    margin-left: -30px;
}
#SWFUpload_1{
	margin-top: 70px;
    margin-left: -30px;
}
</style>
<script>
var contextPath='${contextPath}';
var _contextPath = '${staticServer}';



$(function(){
	$("#type").val("<#if leave??>${leave.type}</#if>");
	$("#center_id").val("<#if leave??>${leave.grade}</#if>");
	$("#username").val("<#if leave??>${leave.username}</#if>");
	$("#reson").val("<#if leave??>${leave.reson}</#if>");
	$("#note").val("<#if leave??>${leave.note}</#if>");
	$("#audit_result").val("<#if leave??>${leave.audit_result}</#if>");
	
	
});


var addLeave = function(){
	var id = $("#id").val();
	var type = $("#type").val();
	var center_id = $("#region").val();
	var reson = $("#reson").val();
	var username = $("#username").val();
	var note = $("#note").val();
	
	var apply_date = $("#apply_date").val();
	var start_date = $("#start_date").val();
	var end_date = $("#end_date").val();
	var entry_time = $("#entry_time").val();
	var audit_result = $("#audit_result").val();
	
	if(center_id==""){
		infopad.err("请选择中心名称!");
		return;
	}
	if(username==""){
		infopad.err("请选择人员!");
		return;
	}
	if(type==""){
		infopad.err("请选择考勤相关!");
		return;
	}
	if(apply_date==""){
		infopad.err("请选择申请日期!");
		return;
	}
	if(start_date==""){
		infopad.err("请选择开始日期!");
		return;
	}
	if(end_date==""){
		infopad.err("请选择结束日期!");
		return;
	}
	if(entry_time==""){
		infopad.err("请选择入职时间!");
		return;
	}
	if(audit_result==""){
		infopad.err("请选择审批结果!");
		return;
	}
	if(reson==""){
		infopad.err("请选择事由!");
		return;
	}else{
		
	}
	
	$.post("${contextPath}/index/add_leave.json", {
			"id":id,
			"username":username,
			"type":type,
			"reson":reson,
			"center_id":center_id,
			"note":note,
			"audit_result":audit_result,
			"start_date":start_date,
			"end_date":end_date,
			"entry_time":entry_time,
			"apply_date":apply_date,
			
		}, function(ms) {
		    var msg = ms.msg;
		    if(msg!=null && msg=="1"){
				infopad.msg("操作成功！");
				window.location.href="${contextPath}/index/leaveList.htm";
		    }else{
		    	infopad.err("操作失败，请联系管理员！");
		    }
			
	});
};

$(function(){
	$("#username").keyup(function(){
		var nickname = $("#username").val();	
		$.post("${contextPath}/index/getUserByNickname.json", {
			"nickname" : nickname
		}, function(ms) {
			 if(ms.user!=null){
			 	var username = ms.user.username;
			 	$("#target").val(username);
		 }
			
		});
	});
});


</script>
</head>
<input type="hidden" id="id" value="<#if leave??>${leave.id}</#if>">
<body>
	<div id="home_link">
		<ul>
			<li></li>
			<li>&gt;</li>
			<li>组织架构</li>
			<li>&gt;</li>
			<li class="current">添加请假记录</li>
		</ul>
	</div>

	<div id="container">
		<div id="title">添加请假记录</div>
		<table id="infotable">
			
			<tr>
				<th>人员:</th>
				<td >
					<select id="target">
						<option value="">-- 请选择目标 --</option>
						<#if uList??>
							<#list uList as list>
								<option value="${list.username}">${list.nickname}（${list.regions}-${list.departments}-${list.job}）</option>
							</#list>
						</#if>
						
					</select>
					<input id="username" type="text" value="" placeholder="快速搜索" />
				</td>
			
			</tr>
			
			<tr>
				<th>中心名称:</th>
				<td>
				<select id="region">
					<option value="">请选择中心</option>
					<#if offList??>
						<#list offList as list>
							<option value="${list.id}" title="${list.address}">${list.name}</option>
						</#list>
					</#if>
				</select>
				</td>
		
			</tr>
			
			<tr>
				<th>申请时间:</th>
				<td>
					<input type="text" id="apply_date" placeholder="申请时间" value="<#if leave??>${leave.apply_date}</#if>" rel="DATE::Y-m-d" value="" size="14" maxlength="15" readonly="readonly" class="DatePicker_Icon">
				</td>
			</tr>
			<tr>
				<th>入职时间:</th>
				<td>
					<input type="text" id="entry_time" placeholder="入职时间" value="<#if leave??>${leave.entry_time}</#if>" rel="DATE::Y-m-d" value="" size="14" maxlength="15" readonly="readonly" class="DatePicker_Icon">
				</td>
			</tr>
			
			<tr>
				<th>考勤相关:
				<select id="type">
						<option value="">请选择类型</option>
						<option value="1">事假</option>
						<option value="2">病假</option>
						<option value="3">旷工</option>
						<option value="4">婚假</option>
						<option value="5">丧假</option>
						<option value="6">产假</option>
						<option value="7">家长假</option>
						<option value="8">加班</option>
						<option value="9">调休</option>
					</select>
				</th>
				<td>
					<input type="text" id="start_date" placeholder="开始时间" onFocus="WdatePicker({startDate:'%y-%M-01 00:00:00',dateFmt:'yyyy-MM-dd HH:mm:ss',alwaysUseStartDate:true})"/>
					<input type="text" id="end_date" placeholder="结束时间" onFocus="WdatePicker({startDate:'%y-%M-01 00:00:00',dateFmt:'yyyy-MM-dd HH:mm:ss',alwaysUseStartDate:true})"/>
				</td>
			</tr>
			
			<tr>
				<th>事由:</th>
				<td>
					<textArea id="reson" style="width:500px;height:150px;"><#if leave??>${leave.reson}</#if></textArea>
				</td>
			</tr>
			<tr>
				<th>备注:</th>
				<td>
					<textArea id="note" style="width:500px;height:50px;"><#if leave??>${leave.note}</#if></textArea>
				</td>
			</tr>
			<tr>
				<th>审批结果:</th>
				<td>
					<textArea id="audit_result" style="width:500px;height:50px;"><#if leave??>${leave.audit_result}</#if></textArea>
				</td>
			</tr>
			
					
		</table>
		<div id="controlbar">
			<input type="button" class="submit" onclick="addLeave()" value="  保  存  " />
		</div>
	</div>
	
</body>
</html>